function messageSubmit() {
    var name = $("#name").val();
    var message = $("#message").val();
    var email = $("#email").val();
    console.log(name)
    if (name == '' || message == '' || email == '') {
        alert("不能为空")
        return;
    }

    $.ajax({
        url: "/addMessage",
        type: "post",
        data: JSON.stringify({
            name: name,
            email: email,
            message: message
        }),
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        success: function (data) {
            alert("提交成功")
            $("#name").val("");
            $("#message").val("");
            $("#email").val("");
        }
    })

}


function register() {
    var username = $("#username").val();
    var password = $("#password").val();
    var confirmpassword = $("#confirmpassword").val();
    if (password != confirmpassword) {
        alert("两次密码不正确！")
    }

    $.ajax({
        url: "/regist",
        type: "post",
        data: JSON.stringify({
            username: username,
            password: password
        }),
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        success: function (data) {
            if (data.code != 200) {
                alert("注册失败,用户名重复！")
            } else {
                alert("注册成功")
                window.location.href = "./login.html";
            }
        }
    })
}


function login() {
    var username = $("#username").val();
    var password = $("#password").val();

    if (username == '' || password == '') {
        alert("不能为空")
        return;
    }
    $.ajax({
        url: "/login",
        type: "post",
        data: JSON.stringify({
            username: username,
            password: password
        }),
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        success: function (data) {
            if (data.code != 200) {
                alert("登录失败，密码或账户错误！")
            } else {
                alert("登录成功")
                window.location.replace("../admin/lyear_pages_doc.html");
            }
        }
    })
}